
/**
 *  Copyright 2011 classic-commerce
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package ca.ioniq.server.resource.impl;

import java.util.List;

import javax.inject.Inject;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;

import ca.ioniq.server.resource.CartResource;
import ca.ioniq.server.service.CartService;
import ca.ioniq.server.service.exception.CartException;
import ca.ioniq.shared.entity.Cart;
import ca.ioniq.shared.entity.Item;

public class CartResourceImpl implements CartResource {

    private CartService cartService;

    @Inject
    public CartResourceImpl(CartService cartService) {
        this.cartService = cartService;
    }
    
	public void addExistingItemsToCart(Long id, List<Item> items) {
		try {
			cartService.updateCart(id, items);
		} catch (CartException e) {
			throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
		}	
	}

	public Cart get(Long id) {
		return cartService.viewCart(id);
	}

	public Cart put(Cart cart) {
		return cartService.createCart(cart);
	}

}
